/*
 * StrLib.c
 * NtTrace Analyzer
 * @author Gregoire JACOB (gregoire.jacob@orange-ftgroup.com)
 * @date 02/09/2008
 * @version 1.0
 * Basic functions on character and strings to analyze a file.
 */

#include ".\Includes\Analyzer.h"


int strcasecmp(const char *s1, const char *s2){
	while (*s1 != '\0' && tolower(*s1) == tolower(*s2)){
		s1++;
		s2++;
    }
	return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
}

int strncasecmp(const char *s1, const char *s2, size_t n){
	if (n == 0) return 0;
	while (n-- != 0 && tolower(*s1) == tolower(*s2)){
		if (n == 0 || *s1 == '\0' || *s2 == '\0') break;
		s1++;
		s2++;
	}
	return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
}

char * strcasestr (char *haystack, char *needle){
	char *p, *startn = 0, *np = 0;
	for(p = haystack; *p; p++){
		if(np){
			if(toupper(*p) == toupper(*np)){
				if(!*++np) return startn;
			}else np = 0;
		}else if(toupper(*p) == toupper(*needle)){
			np = needle + 1;
			startn = p;
		}
	}
	return 0;
}

int unquote(char * string){
	int i, size = (int)strlen(string)-2;
	if(string[0]=='"'){
		for(i=0;i<size;i++){
			string[i]=string[i+1];
		}
		string[i] ='\0';
	}
}

		





